using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using System.Web.Mvc.Ajax;
using WA.Core.DomainModel;
using WA.Utility.EntityHelpers;

namespace WA.WebUI.Controllers
{
    public class PartnerController : Controller
    {
        //
        // GET: /Partner/

        WA.Core.Managers.PartnersManager parnersManager = new WA.Core.Managers.PartnersManager();

        public ActionResult Index()
        {
            return View();
        }

        //
        // GET: /Partner/Details/5

        public ActionResult Details(int id)
        {
            return View();
        }

        //
        // GET: /Partner/Create

        public ActionResult Create()
        {
            return View();
        } 

        //
        // POST: /Partner/Create

        [AcceptVerbs(HttpVerbs.Post)]
        public ActionResult Create(FormCollection collection)
        {
            try
            {
                // TODO: Add insert logic here
                Partner newPartner = new Partner();
                //newPartner.Address = collection["Address"];

                
               

                UpdateModel<Partner>(newPartner);

                newPartner.Company = CompanyHelper.GetRandomCompanyInstance();

                parnersManager.AddNewPartner(newPartner);

                return RedirectToAction("PartnerList");
            }
            catch
            {
                return View();
            }
        }

        //
        // GET: /Partner/Edit/5
 
        public ActionResult Edit(int id)
        {
            return View();
        }


        
        //
        // POST: /Partner/Edit/5

        [AcceptVerbs(HttpVerbs.Post)]
        public ActionResult Edit(int id, FormCollection collection)
        {
            try
            {
                // TODO: Add update logic here 

                return RedirectToAction("Index");
            }
            catch
            {
                return View();
            }
        }

        public ActionResult PartnerList()
        {
           
           ViewData.Model = parnersManager.GetAllPartners();
           return View();
        }
    }
}
